-- SummonBlacksmith
-- Created by cheny3 Dec/15/2016
-- 召唤兽工坊

-- 初始化
function initSummonBlacksmith(self)
    local class = self.gridData.class;
    local buildingInfo = BuildingBonusM.queryBuildingView(class);

    if not buildingInfo then
        error("获取不到建筑查看配置，元素类型：" .. class);
        return;
    end

    -- 建筑图标
    local iconPath = getLevelItemIconPath(buildingInfo["icon2"]);
    local offsetY = tonumber(buildingInfo["icon_offset_y"]);
    self.icon = ccui.ImageView:create(iconPath);
    self.icon:setTouchEnabled(true);
    self.icon:setPositionY(self.icon:getPositionY() + offsetY);
    self.item:addChild(self.icon);
    self.iconPath = iconPath;

    local function onClicked(sender, eventType)
        if eventType == ccui.TouchEventType.began then
            if self.gridData.state == GRID_STATE_DISABLE then
                -- 已经失效，不处理
                return;
            end

            require "game/ui/form/dungeon/special/UISummonBlacksmith"
            UIMgr.getCurrentScene():removeFormByName("UISummonBlacksmith");
            local uiForm = UISummonBlacksmith.create(self.gridData);
            UIMgr.getCurrentScene():addForm(uiForm);
        end
    end
    self.icon:addTouchEventListener(onClicked);
end
